package com.liaoban.app.helper;

import android.support.annotation.DrawableRes;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.liaoban.app.R;

/**
 * 图片加载工具类
 * Created by ZhangWF(zhangwf0929@gmail.com) on 2017/7/19.
 */

public class ImageHelper {

    public static void load(ImageView iv, String url) {
        load(iv,url, R.mipmap.ic_default_pic);
    }

    public static void load(ImageView iv, String url, int defaultResourceId) {
        if (iv == null) {
            return;
        }
        //Glide.with(iv.getContext()).load(url).placeholder(defaultResourceId).into(iv);
        Glide.with(iv.getContext()).load(url).apply(new RequestOptions().placeholder(defaultResourceId)).into(iv);
    }

    public static void loadNoDefault(ImageView iv, String url) {
        if (iv == null) {
            return;
        }
        Glide.with(iv.getContext()).load(url).into(iv);
    }

    public static void load(ImageView iv, @DrawableRes int res) {
        if (iv == null) {
            return;
        }
        Glide.with(iv.getContext()).load(res).into(iv);
    }

}
